
if (!jsx3.lang.Class.forName("ux.cdb.admin.loan.loanWizard.StudenChoice")) {
  jsx3.lang.Class.defineClass("ux.cdb.admin.loan.loanWizard.StudenChoice", 
  ux.megatron.gui.WizardPanel, 
  null, 
  function(block){
    /**
     * instance initializer
     * @param strName {String} unique name distinguishing this object from all other JSX GUI objects in the JSX application
     * @param vntLeft {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntTop {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntWidth {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param vntHeight {int|String} either a number (i.e, 12, 30, etc) or a number and a unit value (i.e., "25%", "36pt", etc); if a number is passed, pixels will be the assumed unit when painted to screen
     * @param strHTML {String} Text/HTML markup to place in the jsx3.gui.Block instance
     */
    block.prototype.init = function(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML){
      //call constructor for super class (the super expects the name of the object and the function that it is an instance of)
      this.jsxsuper(strName, vntLeft, vntTop, vntWidth, vntHeight, strHTML);
    };
    
    block.prototype.initialize = function(msg){
    	//alert(1);
    	this.matrix = this.get("mtxMain");
    	this.wizard = this.getAncestorOfType("ux.megatron.gui.SteppedWizard");
    	this.dailog = this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder");			
    	this.wizard.Operation = ux.megatron.Main.getServer().getBodyBlock().Operation;

    	if(this.dailog.comeFrom == "customer"){
    		this.wizard.jumpToPanel(null, "wizPane_2");
    		this.wizard.doStepJump(this.dailog.get("step2"));
    		return;
    		/*this.wizard.studentId = studentId;
        this.wizard.studentName = studentName;
        this.wizard.studentCertId = certId;*/
    	}
    	if(this.dailog.Operation == "Edit"){
    		this.wizard.jumpToPanel(null, "wizPane_2");
    		this.wizard.doStepJump(this.dailog.get("step2"));
    		return;
    	}    	
    }
    
    block.prototype.onNext = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
    	if(this.wizard.Operation == "Edit" && !this.wizard.isPrev){
    		return null;
    	}
    	if(this.dailog.comeFrom == "customer"){
    		return null;
    	}
    	if(this.checkLoan()) {
			this.wizard.__studentId = this.matrix.getSelectedNodes().get(0).getAttribute('jsxid');
			this.dailog.__studentId = this.wizard.__studentId;
			this.dailog._lockStudent(this.wizard.__studentId);
			return 'NONE';
    	}else{
    		return "NONE";// return "NONE" to not next panels
    	} 
    }
    
    block.prototype.checkLoan = function() {    	
      var nodes = this.matrix.getSelectedNodes();
      if(nodes.size() >= 1) {
         this.wizard.getMessageLabel().setText("&nbsp;");
         return true;
      }else{
         var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp1_unselect");
         this.wizard.getMessageLabel().setText(tip);;
         return false;
      }
    };
    
    block.prototype.onFinish = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL) {
        	if(!this.checkLoan()) {
      			return "NONE";
    			}
    			
    			var lbl = this.wizard.getMessageLabel();
    			var tipStep2 = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp1_step2validateFail");
    			var tipStep3 = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp2_step3validateFail");
    			var block_loan_step2_gd = this.wizard.get("block_loan_step2_gd");
    			if(block_loan_step2_gd){
    				var result =  block_loan_step2_gd.doValidate();
						if(result != null){							
							lbl.setColor('red');
            	lbl.setText(tipStep2,true);
							return 'NONE';
						}
						lbl.setText('',true);
    			}else if(this.wizard.Operation == "Insert"){
    				lbl.setColor('red');
            lbl.setText(tipStep2,true);
						return 'NONE';
    			}
    			
    			var block_loan_step3_gd = this.wizard.get("block_loan_step3_gd");
    			if(block_loan_step3_gd){
    				var result2 =  block_loan_step3_gd.doValidate();
						if(result2 != null){
							//var tip = ux.megatron.Main.getServer().getDynamicProperty("@cdb@LoanManage@Wizard@WizardSetp2_validateFail");
							lbl.setColor('red');
            	lbl.setText(tipStep3,true);
							return 'NONE';
						}
						lbl.setText('',true);
    			}else if(this.wizard.Operation == "Insert"){
    				lbl.setColor('red');
            lbl.setText(tipStep3,true);
						return 'NONE';
    			}
          this.dialog.get("wizPane_3").onSaveData();
          //this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder").onClose();   //to be delete
          return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onPrev = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
		return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onRevert = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      return null; // return "NONE" to not last status
    }
    
    block.prototype.onCancel = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
		if(this.wizard.__studentId)
			this.dailog._unlockStudent(this.wizard.__studentId);
      this.getAncestorOfType("ux.cdb.admin.loan.loanWizard.LoanBuilder").onClose();
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onCustomNav = function(objWIZARD, objBUTTON, objEVENT, strCURRENTPANEL){
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onBeforeShow = function(objWIZARD, objBUTTON, objEVENT, strLASTPANEL){
    	/*var operation = ux.megatron.Main.getServer().getBodyBlock().Operation;
    	if(operation == "Edit"){
    		alert(this.setButtonStates);
    		this.setButtonStates("buttonPrev:DISABLED");
    	}*/
      if (!this.getChild(0)) {
        var me = this;
        ux.megatron.Main.loadUIResourceAsync(me, "ux.cdb.admin", "ux/cdb/admin/loan/loanWizard/step1/ui/StudenChoiceContent.xml", me, me.initialize);
      }
      return null; // return "NONE" to not advance panels
    }
    
    block.prototype.onAfterHide = function(objWIZARD, objBUTTON, objEVENT, strNEXTPANEL){
      return null; // return "NONE" to not advance panels
    }
  });
}
